package com.xiaobias.a13;

import java.lang.reflect.InvocationHandler;

public class A13 {

    interface Foo {
        void foo();

        int bar();
    }

    static class Target implements Foo {

        @Override
        public void foo() {
            System.out.println("target foo");
        }

        @Override
        public int bar() {
            System.out.println("target bar");
            return 100;
        }
    }

//    interface InvocationHandler {
//        Object invoke(Object proxy, Method method, Object[] args) throws Throwable;
//    }

    public static void main(String[] args) {
        InvocationHandler invocationHandler = (p, method, objects) -> {
            // 1. 功能增强
            System.out.println("before...");
            // 2. 调用目标
//            new Target().foo();
            return method.invoke(new Target(), objects);
        };
        Foo proxy = new $Proxy0(invocationHandler);
        proxy.foo();
        proxy.bar();
    }
}
